#######################################################
# The class of Finite & Real-Time DEVS  
# Author: moonho.hwang@gmail.com
#   Date: Oct.19.2011
#######################################################
from XSY.DEVS.FSTDEVS import *
from XSY.Set.Interval import *

class FRTDEVS(FSTDEVS):
   ''' the class of finite & real-time DEVS M=(X,Y,S,tau,delta_0, delta_x,delta_y). Even though it is derived from FSDEVS, the characteristic functions delta_0, delta_x, and delta_y don't have stochastic features any more, while tau has its codomain is the set of intervals. 
Since the verification can be done in the way of FSDEVS, the non stochastic functions delta_0, delta_x, and delta_y are interpreted in rv_delta_0, delta_x, and rv_delta_y, respectively via generating reachabilty graph of FSDEVS. The users need to override the functions of M instead of these rv_{delta_{0,x,y} }. '''
   def __init__(m, name, parent=None):
      '''constructor:'''
      FSTDEVS.__init__(m, name, parent), 
  
   def ta(m):
      '''time advance'''
      rv_ta = m.rv_tau()
      if isinstance(rv_ta, TInterval): 
         return rv_ta.sample()
      elif isinstance(rv_ta, DRV) and len(rv_ta.table)==1: # see FDDEVS
         return rv_ta.sample()
      elif isnumeric(rv_ta):
         return rv_ta

      raise Exception("Unexpected type of rv_ta!"%function_name())


if __name__ == "__main__":
   print 'mini test of FRTDEVS'
   fg = FRTDEVS("hmh")
   print fg

